
// #ifndef VUE3
import Vue from 'vue'
import App from './App'

import {$http} from '@escook/request-miniprogram'
import store from './store/store.js'

// 封装的展示消息提示的方法
uni.$showMsg = function (title = '数据加载失败！', duration = 1500) {
  uni.showToast({
    title,
    duration,
    icon: 'none',
  })
}
uni.$http=$http

$http._post = $http.post
$http.post = function(url, data){
  return new Promise((resolve, reject)=>{
    if(url==='/api/public/v1/users/wxlogin'){
      resolve({
        data: {"message":{"user_id":56,"user_email_code":null,"is_active":null,"user_sex":"男","user_qq":"","user_tel":"","user_xueli":"本科","user_hobby":"","user_introduce":null,"create_time":1630138976,"update_time":1630138976,"token":"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjU2LCJpYXQiOjE2MzQ1NDExOTcsImV4cCI6MTAwMTYzNDU0MTE5Nn0.Mr4IKIcywzecV0m0mzocciVa6w6alJgS2UtNR0EiRkA"},"meta":{"msg":"登录成功","status":200}}
      })  
    }if(url==='/api/public/v1/my/orders/create'){
      resolve({
        data: {"message":{"order_id":3693,"user_id":56,"order_number":"HMDD20211018000000003693","order_price":0.01,"order_pay":"0","is_send":"否","trade_no":"","order_fapiao_title":"个人","order_fapiao_company":"","order_fapiao_content":"","consignee_addr":"广东省,广州市,海珠区,新港中路397号","pay_status":"0","create_time":1634551262,"update_time":1634551262,"order_detail":null,"goods":[{"id":6823,"order_id":3693,"goods_id":43984,"goods_price":4699,"goods_number":2,"goods_total_price":9398}]},"meta":{"msg":"创建订单成功","status":200}}
      })
    }if(url==='/api/public/v1/my/orders/req_unifiedorder'){
      resolve({
        data: {"message":{"pay":{"timeStamp":"1634551887","nonceStr":"kDpUxCMVdEvdBRcY","package":"prepay_id=wx18181125044151c2a2f54c221f19d00000","signType":"MD5","paySign":"34E00F33D1F4C6E869E65A0F68332080"},"order_number":"HMDD20211018000000003693"},"meta":{"msg":"预付订单生成成功","status":200}}
      })
    }else{
      $http._post(url, data).then(data=>resolve(data)).catch(err=>reject(err))
    }    
  })
}

// 配置请求根路径
$http.baseUrl = 'https://api-hmugo-web.itheima.net'
$http.beforeRequest=function(options){
  uni.showLoading({
    title:'加载中'
  })
  if(options.url.indexOf('/my')!==1){
    options.header = {
      Authorization:store.state.m_user.token
    }
  }
}
$http.afterRequest=function(){
  uni.hideLoading()
}
Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
    store,
    ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
import App from './App.vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app,
  }
}
// #endif